﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SkynetCE.Administration.Views.MgmCategories
{
    public partial class MgmCategoriesView : Form, IMgmCategoriesView
    {
        private MgmCategoriesPresenter _Presenter; 
        public MgmCategoriesPresenter Presenter {
            get {
                if (_Presenter == null)
                {
                    this._Presenter = new MgmCategoriesPresenter();
                    this._Presenter.View = this; 
                }
                return _Presenter; 
            }
        }

        public MgmCategoriesView()
        {
            InitializeComponent();   
            
        }

        #region IViewMaster Members

        public string HelpText
        {
            get { return "";  }
        }

        #endregion

        private void menuClose_Click(object sender, EventArgs e)
        {            
                                 
        }

        private void MgmCategoriesView_Load(object sender, EventArgs e)
        {
            this.Presenter.OnViewReady();
        }

        
        public SkynetCE.Foundation.Model.SkynetModel Model
        {
            set {
                this.dgCategories.DataSource = value.ExamCategories;
            }
        }

        private void menuSelect_Click(object sender, EventArgs e)
        {
            this.Presenter.SetCurrentCategory(this.dgCategories.CurrentRowIndex);
            this.tabControl1.SelectedIndex = 1; 
        }

        private void menuNew_Click(object sender, EventArgs e)
        {            
            this.Presenter.AddNewCategory();  
            this.tabControl1.SelectedIndex = 1;
        }

        private void menuDelete_Click(object sender, EventArgs e)
        {
            this.Presenter.DeleteCategory(this.dgCategories.CurrentRowIndex);
            this.tabControl1.SelectedIndex = 0;
        }

        private void txtTitle_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void dgCategories_CurrentCellChanged(object sender, EventArgs e)
        {
      
        }






        #region IMgmCategoriesView Members


        public string Title
        {
            get
            {
                return this.txtTitle.Text; 
            }
            set
            {
                this.txtTitle.Text = value; 
            }
        }

        public string Description
        {
            get
            {
                return this.txtDescription.Text; 
            }
            set
            {
                this.txtDescription.Text = value; 
            }
        }

        #endregion

        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.tabControl1.SelectedIndex == 0)
            {
                this.menuNew.Enabled = true;
                this.menuSelect.Enabled = true;
                this.menuDelete.Enabled = true; 
            }
            else
            {
                this.menuNew.Enabled = false;
                this.menuSelect.Enabled = false;
                this.menuDelete.Enabled = false; 
            }
        }

        private void menuItem2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void menuItem3_Click(object sender, EventArgs e)
        {
            this.Presenter.SaveCategories();
        }
    }
}